"""
客户数据映射层
"""


class GuestMapper:
    """客户数据映射 - 调用模型的转换方法"""
    
    def to_dict(self, guest, include_relations=False):
        """将Guest模型转换为字典"""
        if not guest:
            return None
        return guest.to_dict(include_relations=include_relations)
    
    def to_list(self, guests, include_relations=False):
        """将Guest列表转换为字典列表"""
        return [guest.to_dict(include_relations=include_relations) for guest in guests]
    
    def from_dict(self, data):
        """从字典提取Guest数据（用于更新）"""
        # 返回可用于更新模型的字典
        update_data = {}
        if 'name' in data:
            update_data['name'] = data['name']
        if 'phone' in data:
            update_data['phone'] = data['phone']
        if 'idNumber' in data:
            update_data['id_number'] = data['idNumber']
        if 'email' in data:
            update_data['email'] = data.get('email')
        if 'address' in data:
            update_data['address'] = data.get('address')
        if 'vipLevel' in data:
            update_data['vip_level'] = data.get('vipLevel', 0)
        if 'totalSpent' in data:
            update_data['total_spent'] = data.get('totalSpent', 0)
        return update_data
